package com.gx.smart.construction.ui.house.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.gx.smart.construction.R;
import com.gx.smart.construction.databinding.ItemRecordItemLayoutBinding;
import com.gx.smart.construction.databinding.ItemRecordItemLayoutV3Binding;
import com.gx.smart.construction.ui.common.adapter.BasePagedListAdapter;
import com.gx.smart.construction.ui.house.model.RoomInfo;

import javax.inject.Inject;

import dagger.hilt.android.qualifiers.ActivityContext;

/**
 * @author: xiaosy
 * 时间: 2022/2/14
 * @Description: 分页paging
 * @Version: 1.0
 **/
public class RecordItemPagingAdapter extends BasePagedListAdapter<RoomInfo, RecordItemPagingAdapter.ViewHolder> {

    private static DiffUtil.ItemCallback<RoomInfo> DIFF_CALLBACK = new DiffUtil.ItemCallback<RoomInfo>()
    {
        @Override
        public boolean areItemsTheSame(@NonNull RoomInfo oldItem, @NonNull RoomInfo newItem)
        {
            return oldItem.id == newItem.id;
        }

        @Override
        public boolean areContentsTheSame(@NonNull RoomInfo oldItem, @NonNull RoomInfo newItem)
        {
            return oldItem.equals(newItem);
        }
    };

    @Inject
    public RecordItemPagingAdapter(@ActivityContext Context context) {
        super(DIFF_CALLBACK, context);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_record_item_layout_v3;
    }

    @Override
    protected ViewHolder onCreateHolder(View view) {
        ItemRecordItemLayoutV3Binding binding = ItemRecordItemLayoutV3Binding.inflate(LayoutInflater.from(mContext), (ViewGroup) view,false );
        return new ViewHolder(binding);
    }


    @Override
    protected void onBindData(ViewHolder holder, RoomInfo item, int position) {
        holder.binding.setItem(item);
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {
        private ItemRecordItemLayoutV3Binding binding;

        ViewHolder(ItemRecordItemLayoutV3Binding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
